<!-- 小包快递订单 -->
<template>
  <div class="page-container">
    <page_breadcrumb :getKeyMethod="init_table_model" @change="change_table_model" pageOption />



    <ex_super_table_page v-bind="option" ref="SuperTablePage" @selection-change="li => selection = li"
      >

    </ex_super_table_page>


    <report_anomaly ref="report_anomaly" :orderTypeList="['INBOUND']" @afterSubmitSuccess="reload()" />

    <!-- 导入 -->
    <importView ref="importRef" @submitSuccess="$refs['SuperTablePage'].reload()" />

    <print_express_waybill ref="printRef" />
  </div>
</template>
<script>
import business_function from "@/common/business_function"

import superTablePageFunction from '@/mixin/super-table-page-function';
import emitOnFunction from '@/mixin/emit-on-function';

import page_table_model_manage from '@/mixin/page_table_model_manage';
import report_anomaly from '@/component/dialog/report_anomaly.vue'

import importView from './dialog/import.vue';

import print_express_waybill from '@/component/print/print_express_waybill'

let emitKey = 'packetOrder=>manage'

export default {

  title: "title_packet_order",
  mixins: [superTablePageFunction, emitOnFunction(emitKey), page_table_model_manage],
  components: { report_anomaly, importView,print_express_waybill },


  data() {
    return {
      selection: [],
      limitDate: null,
      option: {
        search: {
          model: [
            { label: "label_order_code", key: "trackNumber" },
            { label: "label_order_status", key: "status", type: 'select', enum: 'TmsOrderStatusEnum'},
            { label: "label_consignee_address", key: "receiptAddress" },
            { label: "label_logistics", key: "productId", type: 'select', url:this.$url['fms/ExpressProduct'], option:(e) => ({ label: e.productName, value: e.productId }) },
            // { label: "label_channel", key: "supplyId", type: 'select', enum: 'ReceivingCustomerStatusEnum' },

            { label: "label_create_order_date", key: "daterange", type: 'date-picker', attrs: { type: 'datetimerange' }, keyExtra: { _emitKey: 'input', 0: 'createTime1', 1: 'createTime2' } }

          ],
        },
        actionExtra: [
          { label: 'label_base_add', attrs: { type: "primary" }, click: ()=>this.clickCreate() },
          { label: 'label_import',  click: this.importFn },
          { label: 'label_submit_order',  click: this.submitOrderFn },
          { label: 'label_print_face_code',  click: this.printFn },
          // { label: 'label_order_intercept',  click: this.interceptOrderFn },
          // { label: 'label_domestic_face_code_import',  click: this.faceImportFn },
          { label: 'label_export',  click: this.exportExcel },
        ],
        table: {
          url: this.$url['oms/OmsExpressSelectOrder'],
          model: this.init_table_model(),
        }
      },
    };
  },



  methods: {
    option_table_model() {
      return [
        { type: 'selection', clickToggle: true, keyGroup: 'label_table_operate' },
        { key: 'trackNumber', label: 'label_order_code', 'min-width': 140, 'show-overflow-tooltip': true, },
        // { key: 'platformOrderCode', label: 'label_srm_api_order_order_code', 'min-width': 140, 'show-overflow-tooltip': true, },
        // { key: 'platformName', label: 'label_srm_api_service_platform_name', 'min-width': 140, 'show-overflow-tooltip': true, },
        { key: 'totalQuantity', label: 'label_package_number', 'min-width': 140, 'show-overflow-tooltip': true, },
        { key: 'receiptAddress', label: 'label_consignee_address', 'min-width': 140, 'show-overflow-tooltip': true, },
        { key: 'receiptUserName', label: 'label_consignee_person_name', 'min-width': 140, 'show-overflow-tooltip': true, },
        { key: 'receiptContacts', label: 'label_consignee_person_phone', 'min-width': 140, 'show-overflow-tooltip': true, },
        { key: 'receiptPostalCode', label: 'label_consignee_postcode', 'min-width': 140, 'show-overflow-tooltip': true, },
        // { key: 'transportType', label: 'label_tms_waybill_transport_mode', 'min-width': 140, 'show-overflow-tooltip': true, formatter: (r, c, v, i) => this.$enumShow(v, "LogisticsProductsTypeEnum") },
        { key: 'totalVolume', label: 'label_volume', 'min-width': 140, 'show-overflow-tooltip': true, },
        { key: 'totalWeight', label: 'label_weight', 'min-width': 140, 'show-overflow-tooltip': true, },
        // { key: 'inboundType', label: 'label_package_type', 'min-width': 140, 'show-overflow-tooltip': true, },
        { key: 'status', label: 'label_order_status', 'min-width': 140, 'show-overflow-tooltip': true, formatter: (r, c, v, i) => this.$enumShow(v, "TmsOrderStatusEnum") },
        {
          type: 'operate', width: 210, fixed: 'right', operate: [
            {
              label: "label_edit",
              disabled:(row)=>!['DRAFT','AUDIT_REJECT','GET_TRACK_FAIL'].includes(row.status),
              click: (row) => {
                this.clickEdit(row)
              }
            },
            {
              type: 'more',
              items: [
                {
                  label: 'label_view_detail',
                  click: (row) => this.clickDetail(row),

                },
                // { label: 'label_domestic_face_code_import', click: (row) => this.faceImportFn(row) },
                {
                  label: 'label_order_track',
                  click: (row) => {
                    this.$router.push({ path: './track_list', query: { trackNumber: row.trackNumber,trackId:row.id } })
                  },
                  disabled: (row) =>['DRAFT','AUDIT_REJECT','GET_TRACK_FAIL'].includes(row.status),
                },
                // {
                //   label: 'label_report_exception', click: row => {
                //     this['$refs']['report_anomaly'].showNew({
                //       disabledEditInfo: true,
                //       data: {
                //         orderType: 'INBOUND',
                //         orderNo: row.receivingOrderCode,
                //       },
                //       onlySetData: true,
                //     })

                //   }
                // },
              ]
            }
          ],
        },
      ]
    },
    // 新增
    clickCreate(row=undefined) {
      this.$router.push({
        path: './order_operate', query: { id: row ? row.id : '', edit: !!row, emitKey }
      })
    },
    clickEdit(row) {
      this.$router.push({
        path: './order_operate', query: { id: row ? row.id : '', edit: !!row, emitKey }
      })
    },
    // 详情
    clickDetail(row) {
      this.$router.push({
        path: './order_detail', query: { id: row.id, }
      })
    },
    // 导入
    importFn() {
      this.$refs.importRef.show()
    },
    // 提交订单
    submitOrderFn() {
      if (_.isEmpty(this.selection)){
        return this.$message.error(this.$tt("tip_please_select_order"));
      }
      this.$ajax({
        url:this.$url['oms/ExpressBatchSubmit'],
        type: 'json',
        method: 'post',
        data:{
          orderIds:this.selection.map(item=>item.id)
        },
        loading: true,
        success: (res) => {
          this.$message.success(this.$t('tip_submit_success'))
          this.reload()
        },

      })
    },
    printFn(list) {
      if (_.isEmpty(this.selection)){
        return this.$message.error(this.$tt("tip_please_select_order"));
      }
      const printData = this.selection.filter(item=>!['DRAFT','AUDIT_REJECT','GET_TRACK_FAIL'].includes(item.status))
      if (_.isEmpty(printData)){
        return this.$message.error(this.$tt("label_print_packet_tips"));
      }
      this.$refs.printRef.show(printData)
    },
    // 订单拦截
    interceptOrderFn() {

    },
    // 面单导入
    faceImportFn() {

    },
    // 导出
    exportExcel() {
      const params = this.$refs.SuperTablePage.getSearchFormData()

      const ids = []
      this.selection.forEach(item => {
        ids.push(item.id)
      })
      this.$downloadFile({
        url: this.$url['oms/ExpressExportExcel'],
        window: false,
        data: {
          ...params,
          orderIds: ids.toString()
        }
      })
    },
  }
};

</script>
<style></style>
